﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace XSocketServerLib
{
    public class Log2Txt
    {
        string path="Log.txt";
        StreamWriter sw;
        
        public static Log2Txt Insitance { get; private set; }
       
        public Log2Txt()
        {
            SetPath(path);
            if (Insitance == null) Insitance = this;
            else
                throw new Exception("Singleton Error");
        }
        public void SetPath(string path)
        {
            this.path = path;
            sw = new StreamWriter(path);
            sw.Close();
        }
        /// <summary>
        /// Log 2 File
        /// </summary>
        /// <param name="value">String to Log</param>
        public void Log(string value)
        {
            sw = new StreamWriter(path, true);
            sw.WriteLine(DateTime.Now.ToString()+ " : "+ value);
            sw.Close();
        }
        /// <summary>
        /// Log 2 File
        /// </summary>
        /// <param name="o">Object to Log</param>
        public void Log(object o)
        {
            sw = new StreamWriter(path, true);
            sw.WriteLine(DateTime.Now.ToString() + " : " + o.ToString());
            sw.Close();
        }
    }
}
